//
//  ShopTableViewCell.m
//  Tang
//
//  Created by 邓芮 on 15/12/8.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "ShopTableViewCell.h"

@interface ShopTableViewCell ()
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *price;
@property (nonatomic, strong) UIImageView *shop;
@end

@implementation ShopTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        CGFloat x = 10 * KWidth / 414;
        CGFloat iconWith = 50 * KWidth/ 414;
        self.icon = [[UIImageView alloc]initWithFrame:CGRectMake(x * 2, x, iconWith, iconWith)];
        [self.contentView addSubview:self.icon];
        
        CGFloat LabelHeight = 25 * KWidth / 414;
        CGFloat shopWidth = 25 * KWidth / 414;
        self.title = [[UILabel alloc]initWithFrame:CGRectMake(x + self.icon.width + x * 2, x, KWidth - x * 3 - self.icon.width - shopWidth, LabelHeight)];
//        self.title.backgroundColor = [UIColor redColor];
        self.title.textColor = [UIColor lightGrayColor];
        self.title.font = [UIFont systemFontOfSize:16 * KWidth / 414];
        [self.contentView addSubview:self.title];
        
        self.price = [[UILabel alloc]initWithFrame:CGRectMake(self.title.x, x + self.title.height, self.title.width, self.title.height)];
        self.price.textColor = [UIColor redColor];
        self.price.font = [UIFont systemFontOfSize:15 * KWidth / 414];
        [self.contentView addSubview:self.price];
        
        self.shop = [[UIImageView alloc]initWithFrame:CGRectMake(KWidth - shopWidth - 10 * KWidth /  414, 35 * KWidth / 414, shopWidth, shopWidth)];
        [self.contentView addSubview:self.shop];
        
    }
    return self;
}

- (void)setModel:(ProductModel *)model
{
    _model = model;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.pic]];
    self.title.text = model.title;
    self.price.text = [NSString stringWithFormat:@"¥%@", model.price];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 80 * KWidth / 414, KWidth, 10 * KWidth / 414)];
    self.shop.image = [UIImage imageNamed:@"shopping"];
    label.backgroundColor = [UIColor colorWithRed:240 / 255.0 green:240 / 255.0 blue:240 / 255.0 alpha:1];
    [self.contentView addSubview:label];
    
}

+ (CGFloat)heightForCell:(ProductModel *)model
{
    return 90 * KWidth / 414;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
